package me.grm.cs.factory;

import me.grm.cs.course.CourseInfo;
import me.grm.cs.course.ICourse;
import me.grm.cs.database.IDatabase;
import me.grm.cs.database.TextDatabase;

import java.lang.reflect.InvocationTargetException;

public class postgradStudentFactory implements ICourseFactory{
    @Override
    public ICourse selectCourse(int index) {
        IDatabase database = TextDatabase.getInstance();
        CourseInfo courseInfo = database.getCourseInfo(index);
        try {
            Class cls = Class.forName(courseInfo.className);
            return (ICourse) cls.getConstructors()[0].newInstance(courseInfo.id, courseInfo.name, courseInfo.className);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }

        return null;
    }
}
